package com.sinopec.pi.scalaguide

import scala.language.implicitConversions

// 可以将 String 对象转换为 BA 对象，提供一组方法
class BA(val name: String) {
    def bark(): Unit = println(s"$name is barking")
}

object Context {
    // 单个方法
    implicit def toBA(name: String): BA = new BA(name)
}

object Implicits {
    def main(args: Array[String]): Unit = {
        // String 类添加方法 bark
        import Context._

        val dog = "dog"
        dog.bark()

    }
}

